package com.labichaoka.chaoka.ui.home.fragment.my.message;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.RelativeLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.labichaoka.chaoka.R;
import com.labichaoka.chaoka.base.BaseActivity;
import com.labichaoka.chaoka.entity.MessageListResponse;
import com.labichaoka.chaoka.utils.ToastUtils;

import butterknife.BindView;

public class MessageActivity extends BaseActivity implements MessageView {

    @BindView(R.id.message_list)
    RecyclerView messageList;
    @BindView(R.id.empty_layout)
    RelativeLayout emptyLayout;
    private MessagePresenter presenter;

    @Override
    protected int initLayoutId() {
        return R.layout.activity_message;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {
        presenter = new MessagePresenterImpl(new MessageInteractorImpl(), this);
        presenter.getMessageList();

        messageList.setLayoutManager(new LinearLayoutManager(this));
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void showProgress() {
        showLoadingProgress();
    }

    @Override
    public void hideProgress() {
        hideLoadingProgress();
    }

    @Override
    public void showMessage(String str) {
        ToastUtils.show(str);
    }

    @Override
    public void setData(MessageListResponse response) {
        if (response==null||response.getData()==null||response.getData().size()==0){
            messageList.setVisibility(View.GONE);
            emptyLayout.setVisibility(View.VISIBLE);
            return;
        }
        BaseQuickAdapter adapter=new MessageAdapter(mContext,response.getData());
        messageList.setAdapter(adapter);
        adapter.setOnItemClickListener((adapter1, view, position) -> {
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        presenter.onDestroy();
    }
}
